package com.whq.mvc.base.redis;

import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

import java.util.concurrent.TimeUnit;

public class RedissonDemo {
    public static void main(String[] args) {
        RedissonUtils redissonUtils = RedissonUtils.getInstance();
        RedissonClient redisson = redissonUtils.getRedisson("127.0.0.1", "6379");
        RLock lock = redisson.getLock("lock");
        lock.lock();
        try {
            System.out.println("抢到锁了");
            RBucket<Object> whq = redisson.getBucket("whq");
            whq.set("wuhaiqiang", 30, TimeUnit.SECONDS);
        } finally {
            lock.unlock();
            redissonUtils.closeRedisson(redisson);
        }
    }
}
